package com.ruoyi.system.service.impl;

import java.util.ArrayList;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.his.domain.WarnHospitalLog;
import com.ruoyi.his.domain.WarnPreLog;
import com.ruoyi.his.domain.vo.WarnMenuItemVo;
import com.ruoyi.his.service.IWarnHospitalLogService;
import com.ruoyi.his.service.IWarnPreLogService;
import com.ruoyi.system.domain.HisChildBeyondWarning;
import com.ruoyi.system.domain.HisLicensedOverWarning;
import com.ruoyi.system.domain.HisVerifyOverdueWarning;
import com.ruoyi.system.service.IHisEngineAnalysisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.mapper.HisEngineRuleGroupMapper;
import com.ruoyi.system.domain.HisEngineRuleGroup;
import com.ruoyi.system.service.IHisEngineRuleGroupService;

/**
 * 预警规则组合Service业务层处理
 *
 * @author Alan
 * @date 2024-03-07
 */
@Service
public class HisEngineRuleGroupServiceImpl implements IHisEngineRuleGroupService
{
    @Autowired
    private HisEngineRuleGroupMapper hisEngineRuleGroupMapper;

    @Autowired
    private IWarnHospitalLogService iWarnHospitalLogService;

    @Autowired
    private IWarnPreLogService iWarnPreLogService;

    @Autowired
    private IHisEngineAnalysisService hisEngineAnalysisService;
    /**
     * 查询预警规则组合
     *
     * @param id 预警规则组合主键
     * @return 预警规则组合
     */
    @Override
    public HisEngineRuleGroup selectHisEngineRuleGroupById(Long id)
    {
        return hisEngineRuleGroupMapper.selectHisEngineRuleGroupById(id);
    }

    /**
     * 查询预警规则组合列表
     *
     * @param hisEngineRuleGroup 预警规则组合
     * @return 预警规则组合
     */
    @Override
    public List<HisEngineRuleGroup> selectHisEngineRuleGroupList(HisEngineRuleGroup hisEngineRuleGroup)
    {
        return hisEngineRuleGroupMapper.selectHisEngineRuleGroupList(hisEngineRuleGroup);
    }

    /**
     * 新增预警规则组合
     *
     * @param hisEngineRuleGroup 预警规则组合
     * @return 结果
     */
    @Override
    public int insertHisEngineRuleGroup(HisEngineRuleGroup hisEngineRuleGroup)
    {
        hisEngineRuleGroup.setCreateTime(DateUtils.getNowDate());
        return hisEngineRuleGroupMapper.insertHisEngineRuleGroup(hisEngineRuleGroup);
    }

    /**
     * 修改预警规则组合
     *
     * @param hisEngineRuleGroup 预警规则组合
     * @return 结果
     */
    @Override
    public int updateHisEngineRuleGroup(HisEngineRuleGroup hisEngineRuleGroup)
    {
        return hisEngineRuleGroupMapper.updateHisEngineRuleGroup(hisEngineRuleGroup);
    }

    /**
     * 批量删除预警规则组合
     *
     * @param ids 需要删除的预警规则组合主键
     * @return 结果
     */
    @Override
    public int deleteHisEngineRuleGroupByIds(Long[] ids)
    {
        return hisEngineRuleGroupMapper.deleteHisEngineRuleGroupByIds(ids);
    }

    /**
     * 删除预警规则组合信息
     *
     * @param id 预警规则组合主键
     * @return 结果
     */
    @Override
    public int deleteHisEngineRuleGroupById(Long id)
    {
        return hisEngineRuleGroupMapper.deleteHisEngineRuleGroupById(id);
    }

    /**
     * 预警规则动态展示的业务
     * @return
     */
    @Override
    public List<HisEngineRuleGroup> selectHisEngineRuleGroupMyList() {
        List<HisEngineRuleGroup> list = hisEngineRuleGroupMapper.selectRuleGroupList();
        ArrayList rlist = new ArrayList();
        for(HisEngineRuleGroup item : list){
            WarnMenuItemVo vo =  new WarnMenuItemVo();
            long typeId = item.getId();
            vo.setText(item.getName());
            Integer analysisWarnCount = hisEngineRuleGroupMapper.getAnalysisWarnCountZz(typeId);
            vo.setNum(analysisWarnCount);
            if(typeId == 8l){
                //执业许可证过期预警
                vo.setPath("/pre-warning-management/license-overdue");
            }
            if (typeId ==18l){
                vo.setPath("/pre-warning-management/check-overdue");
            }
            if(typeId == 12l){
                vo.setPath("/pre-warning-management/child-warn");
            }
            if (typeId == 23l) {
                vo.setPath("/pre-warning-management/physician-skip-level");
            }
            rlist.add(vo);
        }

        return rlist;
    }
}
